package ofpof.domain;

import java.util.Date;

import org.bson.types.ObjectId;

public class RemembermeToken extends Entity {
	private String email;
	private String token;
	private Date lastLogin;
	
	public String getEmail() {
		return email;
	}
	public void setEmail(String email) {
		this.email = email;
	}
	public String getToken() {
		return token;
	}
	public void setToken(String token) {
		this.token = token;
	}
	public Date getLastLogin() {
		return lastLogin;
	}
	public void setLastLogin(Date lastLogin) {
		this.lastLogin = lastLogin;
	}
	public String asCookieString() {
		StringBuffer buffer = new StringBuffer();
		buffer.append(email);
		buffer.append("-");
		buffer.append(token);
		buffer.append("-");
		buffer.append(getId().toString());
		return buffer.toString();
	}
	
	public static RemembermeToken fromString(String tokenValue) {
		String[] split = tokenValue.split("-");
		RemembermeToken remembermeToken = new RemembermeToken();
		remembermeToken.setEmail(split[0]);
		remembermeToken.setToken(split[1]);
		remembermeToken.setId(new ObjectId(split[2]));
		return remembermeToken;
	}
}
